// rgImageFile.h

#ifndef _RG_IMAGE_FILE_H__
#define _RG_IMAGE_FILE_H__

#include <string>
#include <fstream>
#include <iostream>

class rgImageFile
{
public:

	rgImageFile()
	{
		newLine = 0x0a;
	}

	/*rgImageFile(const string& fn, const unsigned int width, const unsigned int height)
	{
		newLine = 0x0a;
		
		mFileName = fn;
		mFile.open(mFileName.c_str(), ios::binary);
		mFile << "P6 " << width << " " << height << " 255" << newLine;

	}
*/

	//file << "P3\n" << this->mViewWidth<<" "<<this->mViewHeight<<"\n255\n";
	//file << r << (unsigned char)(b * 255.0) << (unsigned char)(b * 255.0);


	rgImageFile(const char* fn, const unsigned int width, const unsigned int height)
	{
		newLine = 0x0a;
		
		mFileName = fn;
		mFile.open(mFileName.c_str(), ios::binary);
		mFile << "P6 " << width << " " << height << " 255" << newLine;
	}

	void setFile(const char* fn, const unsigned int width, const unsigned int height)
	{
		newLine = 0x0a;
		
		mFileName = fn;
		mFile.open(mFileName.c_str(), ios::binary);
		mFile << "P6 " << width << " " << height << " 255" << newLine;
	}


	void addData(float& r, float& g, float& b)
	{
		mFile << (unsigned char)(r * 255.0f) << (unsigned char)(g * 255.0f) << (unsigned char)(b * 255.0f);
	}
	
	void addData(rgRGB& color)
	{
		mFile << (unsigned char)(color.r * 255.0f) << (unsigned char)(color.g * 255.0f) << (unsigned char)(color.b * 255.0f);
	}

	// Variables

	unsigned char newLine; // = 0x0a;
	ofstream mFile;
	string mFileName;
};

#endif // _RG_IMAGE_FILE_H__